package com.knight.dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class DynamicSubject implements InvocationHandler {

    private RealSubject realSubject;

    public DynamicSubject(RealSubject realSubject) {
        this.realSubject = realSubject;
    }

    /**
     *
     * @param proxy 生成的代理对象
     * @param method 调用目标对象的方法
     * @param args 调用目标对象的方法参数
     * @return
     * @throws Throwable
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("proxy:"+proxy.getClass());
        System.out.println("before invoke");
        Object returnObject = method.invoke(realSubject, args);
        System.out.println("after invoke");
        return returnObject;
    }
}
